<?php

namespace Modules\Slider\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Modules\Slider\Entities\Slider;

class SliderController extends Controller
{
    /**
     * Display a listing of the resource.
     * @return Response
     */
    public function index()
    {
    	$data = Slider::paginate(10);
        return view('slider::slider.index',compact ('data'));
    }

    /**
     * Show the form for creating a new resource.
     * @return Response
     */
    public function create()
    {
        return view('slider::slider.create');
    }

    /**
     * Store a newly created resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function store(Request $request)
    {
    	Slider::create($request->all());
    	session ()->flash ('success','轮播图添加成功');
    	return redirect ()->route ('slider.index');
    }

    /**
     * Show the specified resource.
     * @return Response
     */
    public function show()
    {
        return view('slider::show');
    }

    /**
     * Show the form for editing the specified resource.
     * @return Response
     */
    public function edit($id)
    {
    	$slider = Slider::find($id);
        return view('slider::slider.edit',compact ('slider'));
    }

    /**
     * Update the specified resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function update(Request $request,$id)
    {
    	$slider = Slider::find($id);
    	$slider->title = $request->input ('title');
    	$slider->thumb = $request->input ('thumb');
    	$slider->url = $request->input ('url');
    	$slider->is_show = $request->input ('is_show');
    	$slider->save();
    	session ()->flash ('success','轮播图编辑成功');
    	return redirect ()->route ('slider.index');
    }

    /**
     * Remove the specified resource from storage.
     * @return Response
     */
    public function destroy($id)
    {
    	Slider::destroy ($id);
		session ()->flash ('success','轮播图删除成功');
		return back ();
    }
}
